<%@ page isELIgnored="false" contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="com.lagou.edu.dao.ResumeDao,com.lagou.edu.pojo.Resume"%>
<%@ page import="java.util.List" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>表格</title>
</head>

<body>
<%
    //取得域对象中的内容
    List<Resume> list = (List<Resume>)request.getAttribute("list");
%>
<table border="1" align="center">
    <caption>简      历</caption>

    <tr>
        <th style="display: none">id</th>
        <th>姓名</th>
        <th>地址</th>
        <th>电话</th>
        <td>操作</td>
    </tr>
    <%
        for(Resume resume : list){
    %>
    <tr>
        <form method="post" action="/resume/edit">
        <th style="display: none"><input type="text" readonly="true" name="id"  value="<%=resume.getId()%>"/></th>
        <th><input type="text"  name="name" value="<%=resume.getName()%>"/></th>
        <th><input type="text" name="address" value="<%=resume.getAddress()%>"/></th>
        <th><input type="text" name="phone" value="<%=resume.getPhone()%>"/></th>
        <td><input type="submit" value="编 辑"/>
<%--            <a href="#" onclick="edit(<%=resume.getId()%>,'<%=resume.getName()%>','<%=resume.getAddress()%>','<%=resume.getPhone()%>')">编辑</a>  --%>
            <a href="#" onclick="del(<%=resume.getId()%>)">删除</a></td>
        </form>
    </tr>
    <%
        }
    %>
    <tr>
    <form method="post" action="/resume/save">
    <th style="display: none"><%=(list.size()+1)%></th>
    <th><input type="text"  name="name"  /></th>
    <th><input type="text"  name="address" /></th>
    <th><input type="text" name="phone" /></th>
    <td><input type="submit" value="新增"/>    </td>
    </form>
    </tr>

</table>
</body>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
    function del(i) {
        $.ajax({
            url: '/resume/delete/'+i,
            type: "get",
            async: false,
            dataType: 'json',
            contentType: 'application/json;charset=utf-8',
            success: function(data) {
                if (data.success) {
                    <%--window.location = '${createLink(controller: 'systemUser ', action: 'indexs ')}';--%>
                    alert("删除成功");
                    window.location ='/resume/queryAll';
                } else {
                    alert("删除异常！");
                }
            },
            error: function() {
                alert("系统异常，请稍后重试！");
            }
        });
    };
    function edit(id,name,address,phone) {
        var data={
            id:id,
            name:name,
            address:address,
            phone:phone,
        };
        $.ajax({
            url: '/resume/edit',
            type: "post",
            data:JSON.stringify(data),
            async: false,
            dataType: 'json',
            contentType: 'application/json;charset=utf-8',
            success: function(data) {
                if (data.success) {
                    <%--window.location = '${createLink(controller: 'systemUser ', action: 'indexs ')}';--%>
                    alert("更新成功");
                    window.location ='/';
                } else {
                    alert("更新异常！");
                }
            },
            error: function() {
                alert("系统异常，请稍后重试！");
            }
        });
    }


</script>
</html>